<?php
class Pxkaoshi_ctl extends Ctl{
    function __construct(){
    }
    function main(array $xxfget) {
        $this::sessver();
        $type=!empty($_POST['type'])?$_POST['type']:false;
        $type=!empty($xxfget['type'])?$xxfget['type']:$type;
        if(!$type){
        	$result=xdb::getInstance()->getarray("select kaiqikaoshi,xinfuxun,stime,etime,realname,pname,shiqi,p.id as pid,p.atime as ptime,shifouchuti from peixunban as p,user u where p.bzrid=u.id and p.xinfuxun like '复训'");
        	$bzr=xdb::getInstance()->getarray("select id,realname from user where id in (select uid from user_groupx where gid=".(gconf('web', 'bzrid')).")");
        	$this::show('pxkaoshi',compact('result','bzr'));
        }elseif($type=="chuti1"){
            $pid=$_POST['pid'];
            echo xdb::getInstance()->getjson("select id from peixunxueyuan where pid=$pid",ARRAY_N);
        }elseif($type=="chuti2"){
            $pxxyid=$_POST['pxxyid'];
            $zhengbukao=array('正考','补考');
            foreach ($zhengbukao as $str){
                $array=array();
                $array2=array();
                $array['pxxyid']=$pxxyid;
                $array['zhengbukao']=$str;
                $array['status']='未考';
                $array2['pxxyid']=$pxxyid;
                $array2['zhengbukao']=$str;
                xdb::getInstance()->indb("pxshijuan", $array, $array2);
                $pxsjid=xdb::getInstance()->getvar("select max(id) from pxshijuan");
                $chuticelue=array(
                    array('kaoheduixiang'=>'合格证','zhishidian'=>'法律法规','tixing'=>'判断','tishu'=>10),
                    array('kaoheduixiang'=>'合格证','zhishidian'=>'其他','tixing'=>'判断','tishu'=>40),
                    array('kaoheduixiang'=>'合格证','zhishidian'=>'法律法规','tixing'=>'单选','tishu'=>8),
                    array('kaoheduixiang'=>'合格证','zhishidian'=>'其他','tixing'=>'单选','tishu'=>32),
                    array('kaoheduixiang'=>'合格证','zhishidian'=>'其他','tixing'=>'多选','tishu'=>10)
                );
                foreach ($chuticelue as $row){
                    $ti=xdb::getInstance()->getarray("select * from pxtiku where kaoheduixiang like '".$row['kaoheduixiang']."' and zhishidian like '".$row['zhishidian']."' and tixing like '".$row['tixing']."' order by rand() limit ".$row['tishu']);
                    $this->chuti($ti, $pxsjid);
                }
            }
            if($_POST['fi']==($_POST['len']-1)){
                xdb::getInstance()->query("update peixunban set shifouchuti='是',kaiqikaoshi='未开启' where id=".$_POST['pid']);
            }
        }elseif($type=="kaiqi"){
            $flog=$_POST['flog'];
            $pid=$_POST['pid'];
            $kaiqi=array(0=>'未开启',1=>'开启');
            $array=array('kaiqikaoshi'=>$kaiqi[$flog]);
            $array2=array('id'=>$pid);
            xdb::getInstance()->updb("peixunban", $array, $array2);
        }elseif($type=="kaoshi"){
            $pid=$xxfget['pid'];
            $result=xdb::getInstance()->getarray("select * from peixunxueyuan where pid=$pid");
            $this::show('pxkaoshixiangxi',compact('result'));
        }
    }
    function chuti($ti,$pxsjid){
        foreach ($ti as $row){//添加正考其他单选32道
            $array=array();
            $array2=array();
            $array['pxsjid']=$pxsjid;
            $array['pxtikuid']=$row['id'];
            $array['kaoheduixiang']=$row['kaoheduixiang'];
            $array['zhishidian']=$row['zhishidian'];
            $array['timian']=$row['timian'];
            $array['xuanxiang']=$row['xuanxiang'];
            $array['biaozhundaan']=$row['biaozhundaan'];
            $array['tixing']=$row['tixing'];
            $array['nanyidu']=$row['nanyidu'];
            $array2['id']=0;
            xdb::getInstance()->indb("pxkaoshiti", $array, $array2);
        }
    }
}